
这个 VPS 是 LNMP 模式部署的.今天刚好有空,看到 nginx 已经是 2016 年的版本了.所以就顺便升级一下.整个过程大概用了 5 分钟.还好吧.很简单,方法如下:
准备工作
在 shell 上使用命令"nginx -V",查看原来 Nginx 的版本和编译信息.你会得到类似的信息
face@zen:~# nginx -V nginx version: nginx/1.12.1 built by gcc 4.7.2(Debian 4.7.2-5) built with OpenSSL 1.0.1t 3 May 2016 TLS SNI support enabled configure arguments: --sbin-path=/usr/sbin --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
!注意,建议用记事本复制configure arguments:后面的信息.因为等会编译新的nginx时候需要使用.
使用wget下载最新版本的nginx,建议选择Stable版本.
地址:http://nginx.org/en/download.html
开始编译(下面步骤都在shell上完成)
configure
解压文件
tar -zxf nginx-1.15.8.tar.gz执行configure命令
./configure --sbin-path=/usr/sbin --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module!注意:这个 configure 参数直接复制准备工作环节保存的原参数,一定要原参数
make
make备份旧 nginx
configure 参数里面有个--sbin-path,那个参数指的就是 nginx 安装位置.我的是/usr/sbin,所以我用下面的命令备份:
mv /usr/sbin/nginx /usr/sbin/nginx_old_1.12.1替换 nginx
cp objs/nginx /usr/sbin测试 nginx 配置文件
nginx -t重启 nginx
nginx -s stop nginx结束语
完成上面的步骤,你可以使用 nginx -V 命令看下是不是最新版本了.很简单:D